// 缓存部门信息
async function queryDepartment() {
  let
    res = null,
    department = localStorage.getItem('department');
  // 判断缓存是否存在，并判断时效性
  if (department) {
    localData = JSON.parse(department);
    if (new Date().getTime() - department.time < 86400000) {
      res = localData.data;
      return res
    }
  }
  // 不使用缓存
  res = await axios.get('/department/list');
  localStorage.setItem('department', JSON.stringify({
    time: new Date().getTime(),
    data: res
  }))
  return res
}


// 缓存工作信息
async function queryJob() {
  let
    res = null,
    job = localStorage.getItem('job');
  // 判断缓存是否存在，并判断时效性
  if (job) {
    localData = JSON.parse(job);
    if (new Date().getTime() - job.time < 86400000) {
      res = localData.data;
      return res
    }
  }
  // 不使用缓存
  res = await axios.get('/job/list');
  localStorage.setItem('job', JSON.stringify({
    time: new Date().getTime(),
    data: res
  }))
  return res
}

// 解析urlencoded信息
(() => {
  function getUrlEncodedParams() {
    let
      reg = /([^?#&=]+)=([^?#&=]+)/g,
      obj = {}
    this.replace(reg, (_, atom1, atom2) => {
      obj[`${atom1}`] = atom2
    })
    return obj
  }
  window.String.prototype.getUrlEncodedParams = getUrlEncodedParams
})()